package cn.maidouya.basic.service.impl;

import cn.maidouya.basic.mapper.BaseMapper;
import cn.maidouya.basic.query.BaseQuery;
import cn.maidouya.basic.service.BaseService;
import cn.maidouya.basic.util.PageLIst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public PageLIst<T> queryData(BaseQuery baseQuery) {
        Integer count = baseMapper.queryCount(baseQuery);
        List<T> list = baseMapper.queryData(baseQuery);
        PageLIst<T> pageLIst = new PageLIst<>(count, list);
        return pageLIst;
    }

}